<?php
	//Annonce
	class Advert extends Model{

		//constructeur
		public function __construct($idAdvert, $idUser, $dateDeposit){
			parent::__construct('advert');
			$this->idAdvert=$idAdvert;
			$this->idUser=$idUser;
			$this->dateDeposit=$dateDeposit;
		}
		
		//Suppression d'une annonce
		public function delete(){
			parent::delete();
			$offer = OfferDB::getOfferByIdAdvert($this->idAdvert);
			if(!is_null($offer)){
				$offer->delete();
				AdvertDB::deleteCriterionsFromIdAdvert($this->idAdvert);
			}else{
				$request = RequestDB::getRequestByIdAdvert($this->idAdvert);
				if(!is_null($request)){
					$request->delete();
					AdvertDB::deleteCriterionsFromIdAdvert($this->idAdvert);
				}
			}
		}
		
		//Retourne vrai si l'annonce est une offre
		public function isOffer(){
			return (!is_null(OfferDB::getOfferByIdAdvert($this->idAdvert)));
		}
		
		//Retourne les criteres d'une annonce
		public function getCriterions(){
			return AdvertDB::getCriterionsFromIdAdvert($this->idAdvert);
		}
		
		//Retourne le logement  d'une annonce
		public function getRoomByIdAdvert(){
			return RoomDB::getRoomByIdAdvert($this->idAdvert);
		}
		
	}
	
?>
